package com.maslyk.invitation.utils;

public class StringUtils
{
	private static char[][] specChars = new char[18][2];
	// 1. Ą - \u0104; ą - \u0105
	// 2. Ć - \u0106; ć - \u0107
	// 3. Ę - \u0118; ę - \u0119
	// 4. Ł - \u0141; ł - \u0142
	// 5. Ń - \u0143; ń - \u0144
	// 6. Ó - \u00d3; ó - \u00f3
	// 7. Ś - \u015a; ś - \u015b
	// 8. Ź - \u0179; ź - \u017a
	// 9. Ż - \u017b; ż - \u017c

	static
	{
		// polskie ogonki
		specChars[0][0] = '\u0104';
		specChars[1][0] = '\u0105';
		specChars[2][0] = '\u0106';
		specChars[3][0] = '\u0107';
		specChars[4][0] = '\u0118';
		specChars[5][0] = '\u0119';
		specChars[6][0] = '\u0141';
		specChars[7][0] = '\u0142';
		specChars[8][0] = '\u0143';
		specChars[9][0] = '\u0144';
		specChars[10][0] = '\u00d3';
		specChars[11][0] = '\u00f3';
		specChars[12][0] = '\u015a';
		specChars[13][0] = '\u015b';
		specChars[14][0] = '\u0179';
		specChars[15][0] = '\u017a';
		specChars[16][0] = '\u017b';
		specChars[17][0] = '\u017c';

		// odpowiedniki ISO Latin1
		specChars[0][1] = 'A';
		specChars[1][1] = 'a';
		specChars[2][1] = 'C';
		specChars[3][1] = 'c';
		specChars[4][1] = 'E';
		specChars[5][1] = 'e';
		specChars[6][1] = 'L';
		specChars[7][1] = 'l';
		specChars[8][1] = 'N';
		specChars[9][1] = 'n';
		specChars[10][1] = 'O';
		specChars[11][1] = 'o';
		specChars[12][1] = 'S';
		specChars[13][1] = 's';
		specChars[14][1] = 'Z';
		specChars[15][1] = 'z';
		specChars[16][1] = 'Z';
		specChars[17][1] = 'z';
	}

	public static String replacePolishSpecialCharacters(String input)
	{
		if(input == null)
			return null;
		
		for (int i = 0; i <= 17; i++)
			input = input.replace(specChars[i][0], specChars[i][1]);

		return input;
	}
	
	public static String replaceUnknownChars(String input)
	{
		input = input.replace('\u2026', '.');
		input = input.replace('\u2018','\'');
		input = input.replace('\u2019','\'');
		input = input.replace('\u201C','"');
		input = input.replace('\u201D','"');
		input = input.replace('\u2013','_');
		input = input.replace('\u2014','_');
		input = input.replace('\u2013','_');
		return input;
	}
}
